package com.cy.springboot04notice.service.aspect;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class SysTimeAspect {

    @Pointcut("@annotation(com.cy.springboot04notice.common.annotation.RequiredTime)")
    public void doTime(){

    }

    @Before("doTime()")
    public void doBefore(){
        System.out.println("@Before");
    }

    @After("doTime()")
    public void doAfter(){
        System.out.println("@After");
    }

    @AfterReturning("doTime()")
    public void doAfterReturning(){
        System.out.println("@AfterReturning");
    }

    @AfterThrowing("doTime()")
    public void doAfterThrowing(){
        System.out.println("@AfterThrowing");
    }

    @Around("doTime()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            log.info("before:{}","@Around.before");
            Object proceed = joinPoint.proceed();
            log.info("AfterReturning:{}","@Around.AfterReturning");
            return proceed;
        }catch (Exception e){
            e.printStackTrace();
            log.info("AfterThrowing:{}","@Around.AfterThrowing");
            throw e;
        }finally {
            log.info("after:{}","@Around.after");
        }
    }
}
